let rec get_lines i = 
  let lines = ref [] in
  try
    while true do
      let line = input_line i in
      lines := line :: !lines
    done ;
    []
  with End_of_file -> List.rev !lines

let write_lines o lines = 
  List.iter 
    (fun line -> 
      output_string o line ;
      output_char o '\n') lines

let () = 
  match Sys.argv with
  | [|_; i; o|] ->
      (try
        let i = open_in i in
        let o = open_out o in
        let lines = get_lines i in
        let lines = List.rev lines in
        write_lines o lines ;
        close_in i ;
        close_out o
      with _ -> ())
  | _ ->
      print_string "usage: input output"